package com.itheima.web; /**
 * @author Xiao
 * @date 2021/8/31
 */

import com.itheima.pojo.User;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet("/userServlet")
public class UserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        ArrayList<User> list = new ArrayList<>();
        list.add(new User("it01","张三", 23, "男",null));
        list.add(new User("it03","李四", 24, "男",null));
        list.add(new User("it05","王五", 25, "男",null));
        list.add(new User("it07","赵六", 26, "男",null));
        list.add(new User("it10","前妻", 27, "女",null));
        request.setAttribute("users", list);
        request.getRequestDispatcher("/user.jsp").forward(request, response); //转发
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
